/******************************************************************************

    Copyright (C) 2006 Alessio Stalla (alessiostalla@gmail.com)

    This file is part of PrettyProlog.

    PrettyProlog is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    PrettyProlog is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with PrettyProlog; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

    See the file COPYING for further details.

 *****************************************************************************/

package prettyprolog.engine.syspreds;

import java.util.List;
import java.util.Vector;


import prettyprolog.datatypes.Substitution;
import prettyprolog.datatypes.Term;
import prettyprolog.datatypes.Variable;
import prettyprolog.engine.Domain;
import prettyprolog.engine.Engine;
import prettyprolog.engine.UnificationAlgorithm;

/**
 * Implements the "=" system predicate. It succeeds when its two arguments can
 * be unified.
 */
public class Unif extends SystemPredicate {

	private static final Unif inst = new Unif();

	private Unif() {
		super(2);
	}

	/** Returns the only instance of this system predicate. */
	public static Unif getInstance() {
		return inst;
	}

	public SyspredEffect doCall(Engine en, Substitution subst, List<Term> args)
			throws SyspredException {
		UnificationAlgorithm unif = en.getUnificationAlgorithm();
		Substitution s2 = unif.unify(args.get(0), args.get(1));
		if (s2 == null)
			return new SyspredEffect(true, subst);
		else

			return new SyspredEffect(false, subst.compose(s2));
	}

	public boolean isBacktrackable() {
		return false;
	}

	public String toString() {
		return super.toString() + " (=)";
	}
}